import { IParam, IContext, DataServiceBase, IHttpResponse } from '@/core';
import { IBIZAPPEXTENDEDITORDTOHelp,  } from '../dto-help/ibizappextendeditor-helps';
import { IBIZAPPEXTENDEDITOR } from '../ibizappextendeditor';
import IBIZAPPEXTENDEDITORKeys from '../ibizappextendeditor-keys';


/**
 * 扩展编辑器服务对象基类
 * 基于template/src/api/{{appEntities}}/data-service/{{appEntities}}-service-base.ts.hbs生成
 *
 * @export
 * @class IBIZAPPEXTENDEDITOR
 * @extends {EntityBaseService}
 */
export class IBIZAPPEXTENDEDITORServiceBase extends DataServiceBase<IBIZAPPEXTENDEDITOR> {

	/**
	 * 存储模式
	 *
	 * @type {(0 | 1 | 3 | 4)} 无本地存储 | 仅本地存储 | 本地及远程存储 | DTO无存储
	 * @memberof IBIZAPPEXTENDEDITORServiceBase
   */
	readonly storageMode: number = 0;

	/**
	 * Creates an instance of IBIZAPPEXTENDEDITORServiceBase.
	 *
	 * @param {*} [opts={}]
	 * @memberof IBIZAPPEXTENDEDITORServiceBase
	 */
	constructor(opts: IParam = {}) {
		super(opts, 'IBIZAPPEXTENDEDITOR');
	}

	/**
	 * 初始化基础数据
	 *
	 * @protected
	 * @memberof IBIZAPPEXTENDEDITORServiceBase
	 */
  protected initBasicData() {
		this.systemName = 'demosys';
		this.appName = 'web';
		this.appEntityName = 'ibizappextendeditor';
		this.appEntityCodeName = 'ibizappextendeditor';
		this.appEntityCodeNames = 'ibizappextendeditors';
    	this.appEntityKeyCodeName = 'ibizappextendeditorid';
      	this.appEntityTextCodeName = 'ibizappextendeditorname';
  	}

	/**
	 * 构造实体
	 *
	 * @protected
	 * @param {IParam} data
	 * @param {IContext} [context]
	 * @return {*} { IBIZAPPEXTENDEDITOR }
	 * @memberof IBIZAPPEXTENDEDITORServiceBase
	 */
	protected newEntity(data: IParam, context: IContext = {}): IBIZAPPEXTENDEDITOR {
    return new IBIZAPPEXTENDEDITOR(data);
  }

	/**
	 * 过滤当前实体服务，标准接口数据
	 *
	 * @return {*}  {*}
	 * @memberof IBIZAPPEXTENDEDITORServiceBase
	 */
	protected filterEntityData(entity: IBIZAPPEXTENDEDITOR): any {
		const data: any = {};
		IBIZAPPEXTENDEDITORKeys.forEach(key => {
				if (entity[key] !== void 0) {
						data[key] = entity[key];
				}
		});
		return data;
	}

  	/**
  	 * CheckKey
  	 *
  	 * @param {IParam} [context={}]
  	 * @param {IParam | IParam[]} [data]
  	 * @returns {Promise<any>}
  	 * @memberof IBIZAPPEXTENDEDITORServiceBase
  	 */
  	public async CheckKey(context: IContext = {}, data: IParam | IParam[]): Promise<any> {
  		data = data ? data : {};
  		let requestPath = '';
  	  	requestPath = `/ibizappextendeditors/checkkey`;
  		data = await IBIZAPPEXTENDEDITORDTOHelp.get(context, data);
  		const res = await this.http.post(requestPath, data);
  			  	return res;
  	}

  	/**
  	 * Create
  	 *
  	 * @param {IParam} [context={}]
  	 * @param {IParam | IParam[]} [data]
  	 * @returns {Promise<any>}
  	 * @memberof IBIZAPPEXTENDEDITORServiceBase
  	 */
  	public async Create(context: IContext = {}, data: IParam | IParam[]): Promise<any> {
  		data = data ? data : {};
  		let requestPath = '';
  	  	requestPath = `/ibizappextendeditors`;
  		if (!data.srffrontuf || data.srffrontuf != 1) {
  			data.ibizappextendeditorid = null;
  		}
  		if (data.srffrontuf != null) {
  			delete data.srffrontuf;
  		}
  		data = await IBIZAPPEXTENDEDITORDTOHelp.get(context, data);
  		const res = await this.http.post(requestPath, data);
  		res.data = await IBIZAPPEXTENDEDITORDTOHelp.set(context, res.data);
  	  	return res;
  	}

  	/**
  	 * Get
  	 *
  	 * @param {IParam} [context={}]
  	 * @param {IParam | IParam[]} [data]
  	 * @returns {Promise<any>}
  	 * @memberof IBIZAPPEXTENDEDITORServiceBase
  	 */
  	public async Get(context: IContext = {}, data: IParam | IParam[]): Promise<any> {
  		data = data ? data : {};
  		let requestPath = '';
  	  	requestPath = `/ibizappextendeditors/${encodeURIComponent(context['ibizappextendeditor'])}`;
  		const res = await this.http.get(requestPath, data);
  		res.data = await IBIZAPPEXTENDEDITORDTOHelp.set(context, res.data);
  	  	return res;
  	}

  	/**
  	 * GetDraft
  	 *
  	 * @param {IParam} [context={}]
  	 * @param {IParam | IParam[]} [data]
  	 * @returns {Promise<any>}
  	 * @memberof IBIZAPPEXTENDEDITORServiceBase
  	 */
  	public async GetDraft(context: IContext = {}, data: IParam | IParam[]): Promise<any> {
  		data = data ? data : {};
  		let requestPath = '';
  	  	requestPath = `/ibizappextendeditors/getdraft`;
  		data['ibizappextendeditor'] = undefined;
  		data['ibizappextendeditorid'] = undefined;
  		const res = await this.http.get(requestPath, data);
  		res.data = await IBIZAPPEXTENDEDITORDTOHelp.set(context, res.data);
  	  	return res;
  	}

  	/**
  	 * Remove
  	 *
  	 * @param {IParam} [context={}]
  	 * @param {IParam | IParam[]} [data]
  	 * @returns {Promise<any>}
  	 * @memberof IBIZAPPEXTENDEDITORServiceBase
  	 */
  	public async Remove(context: IContext = {}, data: IParam | IParam[]): Promise<any> {
  		data = data ? data : {};
  		let requestPath = '';
  	  	requestPath = `/ibizappextendeditors/${encodeURIComponent(context['ibizappextendeditor'])}`;
  		const res = await this.http.delete(requestPath, data);
  	  	return res;
  	}

  	/**
  	 * Save
  	 *
  	 * @param {IParam} [context={}]
  	 * @param {IParam | IParam[]} [data]
  	 * @returns {Promise<any>}
  	 * @memberof IBIZAPPEXTENDEDITORServiceBase
  	 */
  	public async Save(context: IContext = {}, data: IParam | IParam[]): Promise<any> {
  		data = data ? data : {};
  		let requestPath = '';
  	  	requestPath = `/ibizappextendeditors/${encodeURIComponent(context['ibizappextendeditor'])}/save`;
  		data = await IBIZAPPEXTENDEDITORDTOHelp.get(context, data);
  		const res = await this.http.post(requestPath, data);
  			  	return res;
  	}

  	/**
  	 * Update
  	 *
  	 * @param {IParam} [context={}]
  	 * @param {IParam | IParam[]} [data]
  	 * @returns {Promise<any>}
  	 * @memberof IBIZAPPEXTENDEDITORServiceBase
  	 */
  	public async Update(context: IContext = {}, data: IParam | IParam[]): Promise<any> {
  		data = data ? data : {};
  		let requestPath = '';
  	  	requestPath = `/ibizappextendeditors/${encodeURIComponent(context['ibizappextendeditor'])}`;
  		data = await IBIZAPPEXTENDEDITORDTOHelp.get(context, data);
  		const res = await this.http.put(requestPath, data);
  		res.data = await IBIZAPPEXTENDEDITORDTOHelp.set(context, res.data);
  	  	return res;
  	}

  	/**
  	 * FetchDefault
  	 *
  	 * @param {IParam} [context={}]
  	 * @param {IParam | IParam[]} [data]
  	 * @returns {Promise<any>}
  	 * @memberof IBIZAPPEXTENDEDITORServiceBase
  	 */
  	public async FetchDefault(context: IContext = {}, data: IParam | IParam[]): Promise<any> {
  		data = data ? data : {};
  		let requestPath = '';
  	  	requestPath = `/ibizappextendeditors/fetchdefault`;
  		const res = await this.http.get(requestPath, data);
  		res.data = await IBIZAPPEXTENDEDITORDTOHelp.toDataObjArray(context, res.data);
  		return res;
  	}








  	/**
  	 * Select
  	 *
  	 * @param {IParam} [context={}]
  	 * @param {IParam | IParam[]} [data]
  	 * @returns {Promise<any>}
  	 * @memberof IBIZAPPEXTENDEDITORServiceBase
  	 */
  	public async Select(context: IContext = {}, data: IParam | IParam[]): Promise<any> {
  		data = data ? data : {};
  		let requestPath = '';
  	  	requestPath = `/ibizappextendeditors/select`;
  	  	const res = await this.http.get(requestPath);
  	  	return res;
  	}

}